import { ElMessage } from 'element-plus';
import axios from 'axios';

// const user = userStore(store)

const $http = axios.create({
    // 1. 基础地址，超时时间
    timeout: 30000,
    withCredentials: true
})

$http.defaults.headers.post['X-Requested-With'] = 'XMLHttpRequest'
$http.defaults.headers.get['X-Requested-With'] = 'XMLHttpRequest'

$http.interceptors.request.use((config) => {
    return config
}, () => {
    ElMessage.error('网络有问题，请稍后再试')
})

$http.interceptors.response.use((response) => {
    if (response.status !== 200) return
    // if (response.config.responseType === 'arraybuffer') {
       
    //     return response
    // }
    return response.data;
}, (error) => {
    return Promise.reject(error)
})


export default $http